<template>
  <div class="form-layout">
    <!--左侧导航-->
    <div class="nav-left">
      <customAnchor
        :itemList="[
          { name: 'box-base', title: '基础信息' },
        ]"
      />
    </div>
    <!--表单区域-->
    <div class="form-right" ref="formRight">
      <customForm :data="form" :rules="propRules" ref="editForm" :disabled="propReadonly">
        <template #content>
          <div id="box-base" class="box-title">基础信息</div>
          <customFormItem label="设备名称" name="deviceName" :parent="_self" :form="form" disabled
          />
          <customFormItem label="设备编码" name="deviceCode" :parent="_self" :form="form" disabled/>
          <customFormItem label="标签码" name="deviceSn" :parent="_self" :form="form" disabled/>
          <customFormItem label="所属科室" name="deptNameOwner" :parent="_self" :form="form" disabled/>

          <customFormItem label="单机分析" name="flagAlone" :parent="_self" :form="form"  :type="constCommon.formItemType.switch.name" />

          <customFormItem label="数据来源" name="typeSource" :parent="_self" :form="form"
                :type="constCommon.formItemType.selectDict.name" :config="{dictType: constCommon.dictType.deviceTypeSource}"
          />

          <customFormItem label="收入类型" name="typeIn" :parent="_self" :form="form"
                :type="constCommon.formItemType.selectDict.name" :config="{dictType: constCommon.dictType.deviceTypeIn}"
          />

          <customFormItem label="收费项目名称" name="targetName" :parent="_self" :form="form"
              :readonly="true"
              :showSelectIcon="true"
              @focus="$refs.tableDrawerHisCode.show()"
          />
          <customFormItem label="收费项目编码" name="targetCode" :parent="_self" :form="form"  disabled/>
          <customFormItem label="备注" name="remark" :parent="_self" :form="form"  />

        </template>
      </customForm>
    </div>

    <!--his编码选择-->
    <tableDrawer ref="tableDrawerHisCode" refName="tableDrawerHisCode" @confirm="tableDrawerHisCodeConfirm" :viewKey="constCommon.viewKeySelect.matrHis" attach="body"/>
  </div>
</template>

<script>
import customAnchor from '@/components/custom/form/customAnchor.vue'

export default {
  desc: '效益分析设备对照-详情',
  data() {
    return {
      form: {},
    }
  },
  created() {
    this.$emit('event-register', {
      //表单校验
      validate: (callback) => {
        return this.$refs.editForm.validate(callback)
      },

      //保存前操作
      beforeSave: () => {
        this.$emit('data-callback', this.form)
        return true
      },

      //数据加载后
      afterMove: (formData, initData) => {
        this.form = global.utils.jsonClone(formData)
        console.log('set map propInitData', this.propInitData)
        if (this.propParent.cpFormNew) {
          this.$set(this.form, 'ledgerId', this.propInitData.ledgerId)
          this.$set(this.form, 'setId', this.propInitData.id)
          let setArr = ['deviceName','deviceCode','deviceSn','deptNameOwner','deptIdOwner']
          Object.keys(setArr).forEach(index => {
            this.$set(this.form, setArr[index], this.propInitData[setArr[index]])
          })
        }
      },

      //数据保存后
      afterSave: () => {
      },
      beforeDelete: () => {
        return true
      },

      //数据删除后
      afterDelete: () => {
      },

      //流程提交前
      beforeFlow: (flowButtonKey) => {
        return true
      },

      //流程提交后
      afterFlow: (flowButtonKey) => {
      },

      //表单关闭前
      beforeClose: () => {
        return true
      }
    })
  },
  props: {
    //上级对象
    propParent: Object,
    //上级初始化数据
    propInitData: Object,
    //主键字段
    propPrimaryKey: String,
    //数据字典
    propDictionaries: Object,
    //当前操作行
    propCurrentRow: Object,
    //表单数据
    propViewFormData: Object,
    //是否只读
    propReadonly: Boolean,
    //操作状态
    propStatus: String,
    //表单规则
    propRules: Object
  },
  components: {
    customAnchor
  },
  methods: {
    tableDrawerHisCodeConfirm(row) {
      this.$set(this.form, 'targetCode', row.hisCode)
      this.$set(this.form, 'targetName', row.name)
    }
  }
}
</script>
